{include file="head_2" title="图片列表" /}
    <div class="page-wrap">
        <div class="layui-fluid">
            <div class="layui-card">
                <div class="layui-card-body" style="padding: 15px;">
                    <from class="layui-form">
                        <div class="demoTable">
                            名称：
                            <div class="layui-inline">
                                <input class="layui-input" name="name" id="name" value='' autocomplete="off">
                            </div>
                            类型：
                            <div class="layui-inline" autocomplete="off" style="width: 100px;">
                                <select class="layui-input" id="type_id">
                                    <!--<option value="">全部</option>-->
                                    {foreach $pictype as $v } 
                                            <option value="{$v.id}">{$v.name}</option>
                                    {/foreach}   
                                </select>
                            </div>
                            <button class="layui-btn" data-type="reload">搜索</button>
                            <a style=" margin-left: 3em;" href="/admin/piclists/add.html" ><button class="layui-btn layui-btn-primary">添加</button></a>
                            <a style=" margin-left: 3em;" href="/admin/piclists/adds.html" ><button class="layui-btn layui-btn-primary">多添加</button></a>
                        </div>
                    </from>
                    <div style="clear:both"></div>
                    <table class="layui-table" lay-data="{ url:'/admin/piclists/getpic_josn/', page:true, id:'idTest'}" lay-filter="demo">
                        <thead>
                            <tr>
                                <th lay-data="{field:'id',align:'center', width:150}">编号</th>
                                <!--<th lay-data="{field:'name', width:150}">名称</th>-->
                                <th lay-data="{field:'pic', width:150}">图片</th>
                                <th lay-data="{field:'type_id', width:150}">类型</th>
                                <!--<th lay-data="{field:'note', width:150}">介绍</th>-->
                                <th lay-data="{field:'sort', width:150}">排序</th>
                                <th lay-data="{fixed: 'right', width:120, align:'left', toolbar: '#barDemo'}">操作</th>
                            </tr>
                        </thead>
                    </table>

                </div>
            </div>
        </div>
        <script type="text/html" id="barDemo">
            <a class="layui-btn layui-btn-mini" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del">删除</a>
        </script>
    </div>
    
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['layer', 'table', 'jquery'], function () {
        var layer = layui.layer //弹层
                , table = layui.table //表格
                , $ = layui.$;

         var active = {
            reload: function() {
                table.reload('idTest', {
                    where: {
                        key: {
                            name: $('#name').val(),
                            type_id: $('#type_id').val(),
                        }
                    }
                });
            }
        };
        $('.demoTable .layui-btn').on('click', function() {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });   
        
        
        
        //监听工具条
        table.on('tool(demo)', function (obj) {
            var data = obj.data
                    , layEvent = obj.event;
            if (layEvent === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    del_data(obj);
                    layer.close(index);
                    //向服务端发送删除指令
                });
            } else if (layEvent === 'edit') {
                location.href = "/admin/piclists/edit/id/" + data.id;
            }
        });
        function del_data(obj)
        {
            var data = obj.data;
            $.ajax({
                url: "/admin/piclists/del_submit/",
                type: 'post',
                data: {id: data.id},
                dataType: 'json',
                success: function (data) {
                    if (data.code == 1)
                    {
                        layer.msg("删除成功!", {
                            time: 2000
                        }, function () {
                            location.reload();
                        });
                    } else
                    {
                        layer.msg(data.msg);
                    }
                },
            });
        }

    });
</script>
{include file="foot" /}